-
-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add query comment into the query for improved debugging #1082
base: master
Are you sure you want to change the base?
Conversation
b5a3236
to
17bb978
Compare
Looks like it is similar to #1002. |
17bb978
to
b1e4e60
Compare
b1e4e60
to
1376d18
Compare
@@ -66,3 +70,13 @@ func sliceElemType(v reflect.Value) reflect.Type { | |||
} | |||
return indirectType(elemType) | |||
} | |||
|
|||
// appendComment adds comment in the header of the query into buffer | |||
func appendComment(b []byte, name string) []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here need to filter 0x00
appendComment(nil, string([]byte{'*', 0, 0, 0, 0, 0, '/'}))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Added fix + test
Let's move Also, do we want to support a single comment or multiple comments? E.g. what should be the result of calling |
@vmihailenco I can add multicomment support.
But I wonder should they be separeated by the new line line
I suspect there might be a case when we have sharded db and we need to add kind of global instance name in the comment for example when we establishing a connection or via some hook. In this particular case it might be:
What do you think? |
It is not advisable to implement support for multiple comments now. When writing SQL using an ORM, the syntax is relatively unordered; however, comments should maintain a specific sequence. For example: /* maybe we need to write something */
SELECT /* but seem redundant */ 1;
/* say goodbye to db */ |
Closes #998
A common challenge when using ORMs is the difficulty of correlating an executed query in the DBMS with the lines of code that triggered it. To solve this issue, it would be helpful to add a comment in the header of the generated query. In this implementation, if a context with a comment is provided, we’ll include that as a comment in the query.
This feature enhances debugging by including query comments in headers, allowing developers to trace the query's origin. By matching the query comment in the header, it's easier to identify the specific location in the code where the query was executed.
Using this feature uses now can add SQL comment in query header
For example
This will create a query like
This was implemented in go-pg #2011